package java_thinking.unit_11._11_11;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Description : E27
 * 写一个Command类，它包含一个String域和一个显示该String域的方法operation(),写第二个类，
 * 它具有一个使用Command对象来填充一个Queue的方法
 * @author: cww
 * @DateTime: 2019-03-18 21:46
 */

public class Command {
    private final String s ;
    public Command(String cmd){
        this.s = cmd;
    }
    public void operation(){
        System.out.println(s);
    }
}
class Producer{
    public static void produce(Queue<Command> q){
        q.offer(new Command("load"));
        q.offer(new Command("delete"));
        q.offer(new Command("save"));
        q.offer(new Command("exit"));
    }
}

class Consumer {
    public static void consume(Queue<Command> q){
        while (q.peek() != null) {
            q.remove().operation();
        }
    }
}

class E27{
    public static void main(String[] args) {
        Queue<Command> cmds = new LinkedList<>();
        Producer.produce(cmds);
        Consumer.consume(cmds);
    }
}